package com.xiaoju.uemc.tinyid.server.config;

import com.mysql.cj.jdbc.MysqlDataSource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;

/**
 * @author du_imba
 */
@Slf4j
@Configuration
@RequiredArgsConstructor
public class DataSourceConfig {

    private final DataSourceInfo dataSourceInfo;

    @Bean
    public DataSource getDataSource() {
        MysqlDataSource mysqlDataSource = new MysqlDataSource();
        mysqlDataSource.setUrl(dataSourceInfo.getUrl());
        mysqlDataSource.setDatabaseName(dataSourceInfo.getName());
        mysqlDataSource.setUser(dataSourceInfo.getUsername());
        mysqlDataSource.setPassword(dataSourceInfo.getPassword());
        return mysqlDataSource;
    }


}
